<?php

//require_once('../../includes/classes/core.php');
$conn = mysql_connect('217.11.163.234', 'root', 'Gl-1114');
if (!$conn) {
    $error = 'dgfhg';
}
mysql_select_db('asteriskcdrdb');

$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count    = $_REQUEST['count'];
		$hidden   = $_REQUEST['hidden'];
		$start    = $_REQUEST['start'];
		$end      =	$_REQUEST['end'];
		
	  	$rResult = mysql_query("SELECT  id,
                                        calldate,
                                        phone,
                                        ext,
                                        SEC_TO_TIME(duration) AS `duration`,
                                        CONCAT('<p onclick=play(', '\'', file, '\'',  ')>მოსმენა</p>', '<a download=\"audio.wav\" href=\"http://217.11.163.234:8181/', file, '\">ჩამოტვირთვა</a>')
                                FROM out_call
                                WHERE DATE(calldate) >= '$start' AND DATE(calldate) <= '$end'");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>